import { createSlice } from "@reduxjs/toolkit";

const CitySlice = createSlice({
  name: "CitySlice",
  initialState: {
    start: "北京",
    end: "杭州",
  },
  reducers: {
    setCity(state, { payload: { type, city } }) {
      state[type] = city;
    },
    exchangeCity(state) {
      const temp = state.start;
      state.start = state.end;
      state.end = temp;
    },
  },
});

export const { setCity, exchangeCity } = CitySlice.actions;

export default CitySlice.reducer;
